#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

void test()
{
    vector<int> vec;
    vec.push_back(10);
    cout << "size() = " << vec.size() << endl;
    cout << "capacity() = " << vec.capacity() << endl;

    bool flag = true;
    for(auto it = vec.begin(); it != vec.end(); ++it)
    {
        cout << *it << "  ";
        if(flag)
        {
            //在执行push_back底层已经发生了扩容操作，it指向还是老的空间
            //但是vec.end()指向的是新的空间的尾部，这样还在使用老的空间
            //的迭代器it，就会发生失效
            vec.push_back(20);
            flag = false;
            it = vec.begin();
        }
    }
    cout << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

